package myky.com.doctorapp.adapter

import android.text.TextUtils
import android.widget.RelativeLayout
import android.widget.TextView
import com.blankj.utilcode.util.ConvertUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.facebook.drawee.view.SimpleDraweeView
import com.github.nukc.stateview.Constant
import myky.com.doctorapp.R
import myky.com.doctorapp.api.Address
import myky.com.doctorapp.entity.DoctorWrapperEntity
import myky.com.doctorapp.utils.UriUtils

class FindDoctorDoctorAdapter(data: List<DoctorWrapperEntity.DoctorListEntity.DoctorsEntity>?) : BaseQuickAdapter<DoctorWrapperEntity.DoctorListEntity.DoctorsEntity, BaseViewHolder>(R.layout.doctor_item, data) {

    override fun convert(holder: BaseViewHolder, imageParamBean: DoctorWrapperEntity.DoctorListEntity.DoctorsEntity) {

        val view = holder.getView<SimpleDraweeView>(R.id.bespeak_doctor_item_header)

        view.setImageURI(UriUtils.getUriInstance().getUri(Constant.ONLINEPIC, Address.IMAGE.plus(imageParamBean.headPhoto)))

        holder.setText(R.id.bespeak_doctor_item_name, imageParamBean.realname)
        holder.setText(R.id.bespeak_doctor_item_level, imageParamBean.administrationname)
        holder.setText(R.id.bespeak_doctor_item_hospital, imageParamBean.hospitalname)
        holder.setText(R.id.bespeak_doctor_item_ks, imageParamBean.departmentname)
        holder.setText(R.id.bespeak_doctor_item_ms, imageParamBean.speciality)
        holder.addOnClickListener(R.id.item_smallbtn_consoult)
        holder.addOnClickListener(R.id.item_smallbtn_remote)
        holder.addOnClickListener(R.id.item_smallbtn_bespeak)
        holder.addOnClickListener(R.id.ll_doctor_details_top)
        val textView = holder.getView<TextView>(R.id.bespeak_doctor_item_ks)

        val departmentname = imageParamBean.departmentname

        departmentname?.let {
            val ellipsize = TextUtils.ellipsize(it, textView.paint, ConvertUtils.dp2px(120f).toFloat(), TextUtils.TruncateAt.END)
            textView.text = ellipsize
        }

        val rl_consoult = holder.getView<RelativeLayout>(R.id.item_smallbtn_consoult)
        val rl_remote = holder.getView<RelativeLayout>(R.id.item_smallbtn_remote)
        val rl_bespeak = holder.getView<RelativeLayout>(R.id.item_smallbtn_bespeak)
        if (imageParamBean.doctorpermitnew != null) {
            if (imageParamBean.doctorpermitnew.contains("1")) {
                holder.setBackgroundRes(R.id.item_smallbtn_consoult, R.drawable.small_btn_consoult)
                rl_consoult.isClickable = true
                holder.setTextColor(R.id.item_smallbtn_consoult_tv, mContext.resources.getColor(R.color.blue_60c6f1))
            } else {
                rl_consoult.setBackgroundResource(R.drawable.small_btn_gray)
                rl_consoult.isClickable = false
                holder.setTextColor(R.id.item_smallbtn_consoult_tv, mContext.resources.getColor(R.color.gray_d4d4d4))
            }
            if (imageParamBean.doctorpermitnew.contains("2")) {
                rl_remote.setBackgroundResource(R.drawable.small_btn_remote)
                rl_remote.isClickable = true
                holder.setTextColor(R.id.item_smallbtn_remote_tv, mContext.resources.getColor(R.color.orange_ffa77a))
            } else {
                rl_remote.setBackgroundResource(R.drawable.small_btn_gray)
                rl_remote.isClickable = false
                holder.setTextColor(R.id.item_smallbtn_remote_tv, mContext.resources.getColor(R.color.gray_d4d4d4))
            }
            if (imageParamBean.doctorpermitnew.contains("3")) {
                rl_bespeak.setBackgroundResource(R.drawable.small_btn_bespeak)
                rl_bespeak.isClickable = true
                holder.setTextColor(R.id.item_smallbtn_bespeak_tv, mContext.resources.getColor(R.color.green_47d995))
            } else {
                rl_bespeak.setBackgroundResource(R.drawable.small_btn_gray)
                rl_bespeak.isClickable = false
                holder.setTextColor(R.id.item_smallbtn_bespeak_tv, mContext.resources.getColor(R.color.gray_d4d4d4))
            }
        }
    }
}
